<template>
  <div class="bin-chart">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, defineProps, withDefaults, onMounted, watchEffect } from 'vue'

import { EChartsOption } from 'echarts'
import useEchart from '../hooks/use-echart'

const props = withDefaults(
  defineProps<{
    option: EChartsOption
    width?: string
    height?: string
  }>(),
  {
    width: '100%',
    height: '360px'
  }
)

const echartDivRef = ref<HTMLElement>()

onMounted(() => {
  const { setOption } = useEchart(echartDivRef.value!)

  watchEffect(() => {
    setOption(props.option)
  })
})
</script>

<style scoped></style>
